﻿////////////////////////////////////////////////////////
/////	  文件名：index.js                         /////
/////     作  者：黄纲                             /////
/////     时  间：2006.10.30                       /////
/////     描  述：对系统首页控制的客户端脚本       /////
////////////////////////////////////////////////////////

//为JavaScript添加Trim()属性
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//为文本框添加获取焦点事件
function TextBoxGetFource(TextBoxID)
{
    var textBox = document.getElementById(TextBoxID);
    
    if(textBox != null)
    {
        textBox.select();
    }
}

//按回车焦点转移
function FocusChangNext()
{
    if(event.keyCode == 13) 
    {
        event.keyCode = 9;
    }
}

//树型菜单收缩与展开控制
function TreeViewExpanded(Index, ButtonID)
{
    document.getElementById("hidMenuID").value = Index;

    document.getElementById(ButtonID).click();
}

//回车提交数据
function ButtonSubmit(ButtonID)
{
    if(event.keyCode == 13) 
    {
        var button = document.getElementById(ButtonID);
        
        button.click();
    }
}

//DataGrid中回车提交数据
function ChildButtonSubmit(ID, NewID, OldID)
{
    var id = ID.substring(0, ID.indexOf(OldID));
    var buttonId = id + NewID;
    var button = document.getElementById(buttonId);

    if(event.keyCode == 13) 
    {
        button.click();
    }
}

//鼠标双击提交数据
function ImageButtonSubmit(ID, NewID, OldID)
{
    try
    {
        var id = ID.substring(0, ID.indexOf(OldID));
        var buttonId = id + NewID;
        var button = document.getElementById(buttonId);

        button.click();
    }catch(E){}
}

//控制屏幕的收缩和展开
function TabCortrol()
{
    var td1 = document.getElementById("tdLeft");
    var td2 = document.getElementById("tdCenter");
    var td3 = document.getElementById("tdRight");
    
    if(td2.title == "收缩")
    {
        td1.style.width = 0;
        td1.style.display = "none";
        td3.style.width = 1002;
        td2.background = "App_Images/b_2.gif";
        td2.title = "展开";
    }
    else
    {
        td1.style.width = 170;
        td1.style.display = "block";
        td3.style.width = 824;
        td2.background = "App_Images/b_1.gif";
        td2.title = "收缩";
    }
}

//添加Tab菜单窗口
function AddWin(Index, Text, Url, PageID)
{
    var winTab0 = parent.document.getElementById("WinTab0");
    var winTxt0 = parent.document.getElementById("WinTabTxt0");
    var winTab1 = parent.document.getElementById("WinTab1");
    var winTxt1 = parent.document.getElementById("WinTabTxt1");
    var winImg = parent.document.getElementById("WinTabImg");
    
    winTab0.background = "App_Images/b_14.gif";
    winTxt0.color = "#183184";
    winTab1.background = "App_Images/b_13.gif";
    //winImg.src = "App_Images/ico/"+ Index +".gif";
    winTxt1.innerHTML = Text;
    winTxt1.color = "#3A8A39";
    winTab1.style.display = "block";
    
    parent.document.getElementById("hidOpenUrl").value = Url + "?PageID="+ PageID;
    parent.document.getElementById('ifrmRightPage').src= Url + "?PageID="+ PageID +"&setTime=" + new Date().getTime();
}

//切换Tab菜单窗口
function ChangWin(Index, Fig)
{
    var winTab0 = parent.document.getElementById("WinTab0");
    var winTxt0 = parent.document.getElementById("WinTabTxt0");
    var winTab1 = parent.document.getElementById("WinTab1");
    var winTxt1 = parent.document.getElementById("WinTabTxt1");
    var ifrom = parent.document.getElementById("ifrmRightPage");
    
    if(Index == 0)
    {
        winTab0.background = "App_Images/b_15.gif";
        winTxt0.color = "#3A8A39";
        winTab1.background = "App_Images/b_14.gif";
        winTxt1.color = "#183184";
        
        ifrom.src = "frm_RightPage.aspx?id="+ Fig +"&setTime=" + new Date().getTime();
    }
    else
    {
       winTab0.background = "App_Images/b_14.gif";
       winTxt0.color = "#183184";
       winTab1.background = "App_Images/b_13.gif";
       winTxt1.color = "#3A8A39"; 
       
       ifrom.src = parent.document.getElementById("hidOpenUrl").value +"&setTime=" + new Date().getTime();
    }
}

//关闭Tab菜单窗口
function CloseWin()
{
   parent.document.getElementById("WinTab1").style.display = "none";
   parent.document.getElementById("WinTab0").background = "App_Images/b_15.gif";
   parent.document.getElementById("WinTabTxt0").color = "#3A8A39";
   parent.document.getElementById("ifrmRightPage").src = "frm_RightPage.aspx?setTime=" + new Date().getTime();
}

//改变DIV的宽度
function ChangDivWidth()
{
    //debugger;
    var width = parent.document.getElementById("tdRight").style.width;
    var div = document.getElementById("divShowResult");
    //alert(width);

    if(width == "1002px")
    {   
        div.style.width = 990;
    }
    else
    {
        div.style.width = 820;
        
    }
}

//改变Tr的背景颜色
function ChangTrBgColorByDataGrid(CheckBox, NewID, OldID)
{
    var ID = CheckBox.id;
    var id = ID.substring(0, ID.indexOf(OldID));
    var trClientID = id + NewID;
    
    try
    {
        var tr = document.getElementById(trClientID);
        
        if(CheckBox.checked)
        {   
            tr.bgColor = "#D3E2D7";
        }
        else
        {
            tr.bgColor = "";
        }
    }
    catch(e){}
}


//改变Tr的背景颜色
function ChangTrBgColor(Tr, Color)
{
    Tr.bgColor = Color;
}

//切换Image的图片
function ChangImage(Image, Url)
{
    var div = document.getElementById("divChildMenu");
    
    if(div.style.visibility == "hidden")
    {
        Image.src = Url;
    }
}

//下拉菜单显示或隐藏控制
function ChildMenuVisible()
{
    var div = document.getElementById("divChildMenu");
    
    if(div.style.visibility == "hidden")
    {
        div.style.visibility = "visible";
    }
    else
    {
        div.style.visibility = "hidden";
    }
}

function ShowChildMenu(Button, DivID)
{
    var btn = document.getElementById(Button);
    var div = document.getElementById(DivID);
    
    //alert(btn.offsetLeft);

    if(div.style.visibility == "hidden")
    {
        div.style.visibility = "visible";
    }
    else
    {
        div.style.visibility = "hidden";
    }
}

//切换Image的图片(查询)create by kidy on 20061226
function QueryChangImage(Image, Url)
{
    var div = document.getElementById("divChildQuery");
    
    if(div.style.visibility == "hidden")
    {
        Image.src = Url;
    }
}


//查询状态下拉菜单显示或隐藏控制create by kidy on 20061226
function QueryChildMenuVisible()
{
    var div = document.getElementById("divChildQuery");
    
    if(div.style.visibility == "hidden")
    {
        div.style.visibility = "visible";
    }
    else
    {
        div.style.visibility = "hidden";
    }
}

//添加新记录的面板控制
function AddPanelVisible(Index)
{
    var trAdd = document.getElementById("trAdd");
    var hidFalg = document.getElementById("hidFalg");
    
    if(Index == 0)
    {
        var date = new Date();
        var year = date.getYear();
        var month = date.getMonth();
        var day = date.getDay();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        var currTime = year +""+ month +""+ day +""+ hour +""+ minute +""+ second;
        currTime = currTime.substring(2, currTime.length - 2);
        
        if(hidFalg != null)
        {
            var value = hidFalg.value;
            
            if(value == "Open")
            {
                var addIndex = document.getElementById("hidAddIndex").value;
                var ID = addIndex.substring(0, addIndex.indexOf('panShowChildResult'));
                var addClientID = ID + "trAddChild";
                
                document.getElementById(addClientID).style.display = "block";
                document.getElementById(ID + "txt1Child").select();
            }
            else
            {
                trAdd.style.display = "block";

                document.getElementById("txt1").value = "HIS" + currTime;
                document.getElementById("txt2").value = "";
                /*document.getElementById("txt3").value = "";
                document.getElementById("txt9").value = "";*/
                document.getElementById("txt2").select();
            }
        }
        else
        {
            trAdd.style.display = "block";

            document.getElementById("txt1").value = "C" + currTime;
            document.getElementById("txt2").value = "";
            /*document.getElementById("txt3").value = "";
            document.getElementById("txt9").value = "";*/
            document.getElementById("txt2").select();
        }
    }
    else
    {
        if(confirm('您真的要取消新增吗？'))
        {
            if(hidFalg != null)
            {
                var value = hidFalg.value;

                if(value == "Open")
                {
                    var addIndex = document.getElementById("hidAddIndex").value;
                    var ID = addIndex.substring(0, addIndex.indexOf('panShowChildResult'));
                    var addClientID = ID + "trAddChild";
                    
                    document.getElementById(addClientID).style.display = "none";
                }
                else
                {
                    trAdd.style.display = "none";
                }
            }
            else
            {
                trAdd.style.display = "none";
            }
        }
    }
}

//刷新页面
function RefurbishForm(FormID, Url)
{
    var currTime = new Date().getTime();
    var form = document.getElementById(FormID);
    
    form.action = Url + "?setTime=" + currTime;
    form.submit();
}






